package financial.sharing.center.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import financial.sharing.center.common.enums.ResponseContext;
import financial.sharing.center.common.utils.PageSize;
import financial.sharing.center.common.utils.R;
import financial.sharing.center.system.model.entity.TaxRate;
import financial.sharing.center.system.service.TaxRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TaxRateController
 * @Description TODO
 * @Author guoyuhang
 * @ @csdn https://blog.csdn.net/qq_40788718
 * @Date 2021/5/7
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/system/tax/rate/")
public class TaxRateController {

    @Autowired
    private TaxRateService taxRateServiceImpl;

    @PostMapping(value = "get/all/tax/rate")
    public R getAllTaxRate(String selectTaxRegion,
                           String selectTaxType,
                           Integer currentPage){
        PageHelper.startPage(currentPage, PageSize.PAGESIZE_TEN);
        PageInfo<TaxRate> result = this.taxRateServiceImpl.getAllTexRate(selectTaxRegion,selectTaxType);
        return R.ok(result);
    }

    @PostMapping(value = "get/map/tax/rate")
    public Map<Integer,BigDecimal> getTaxRateMap(){
        return this.taxRateServiceImpl.getTaxRateMap();
    }

    @PostMapping(value = "create/one/tax/rate")
    public R createOneTaxRate(String taxRegion,
                              String taxType,
                              BigDecimal rate){
        Integer result = this.taxRateServiceImpl.createOneTaxRate(taxRegion,taxType,rate);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "compile/one/tax/rate")
    public R compileOneTaxRate(@RequestBody TaxRate taxRate){
        Integer result = this.taxRateServiceImpl.compileOneTaxRate(taxRate);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "delete/one/tax/rate")
    public R deleteOneTaxRate(Integer id){
        Integer result = this.taxRateServiceImpl.deleteOneTaxRate(id);
        return R.ok(ResponseContext.int2Enum(result).getName());
    }

    @PostMapping(value = "get/list/tax/rate")
    public R getListTaxRate(){
        List<TaxRate> result = this.taxRateServiceImpl.getListTaxRate();
        return R.ok(result);
    }
}
